package org.testis.wirelesssecuritymodule.core;

import org.testis.utils.StringUtils;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author barisergun
 */
public class WirelessSecurityProtocolWEP extends WirelessSecurityProtocol {

    public WirelessSecurityProtocolWEP(String ssid,
            String pskInfo,
            String iFacename) {
        m_ssid = ssid;
        m_profileString = "network={\n" +
                "ssid=\"" + ssid + "\"\n" +
                "scan_ssid=1\n" +
                "key_mgmt=NONE\n" +
                "wep_key0=\"" + pskInfo + "\"" +
                "}";
       String hexSsid="";
        try {
            hexSsid = StringUtils.stringToHex(ssid, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(WirelessSecurityProtocolWEP.class.getName()).log(Level.SEVERE, null, ex);
        } 

        m_wlanProfileString = "<?xml version=\"1.0\" ?>" +
                "<WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\">" +
                " <name>" + ssid + "</name>" +
                " <SSIDConfig>" +
                "   <SSID>" +
                "      <hex>" + hexSsid + "</hex>" +
                "      <name>" + ssid + "</name>" +
                "    </SSID>" +
                "  </SSIDConfig>" +
                "  <connectionType>ESS</connectionType>" +
                "  <connectionMode>auto</connectionMode>" +
                "  <MSM>" +
                "     <security>" +
                "           <authEncryption>" +
                "              <authentication>open</authentication>" +
                "              <encryption>WEP</encryption>" +
                "              <useOneX>false</useOneX>" +
                "           </authEncryption>" +
                "           <sharedKey>" +
                "               <keyType>networkKey</keyType>" +
                "                <protected>false</protected>" +
                "               <keyMaterial>"+pskInfo+"</keyMaterial>" +
                "            </sharedKey>" +
                "       </security>" +
                "  </MSM>" +
                "</WLANProfile>";
        m_iFaceName = iFacename;
    }
}
